{extend name="layout:base" /}

{block name="content"}
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <form class="layui-form">
                <div class="layui-row layui-col-space10 layui-form-item">
                    <label class="layui-form-label">客户名</label>
                    <div class="layui-input-inline">
                        <input type="text" name="name" lay-verify="required" autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux">
                        如网站名和客户名不同则  客户名(网站名)
                    </div>
                </div>

                <div class="layui-row layui-col-space10 layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">签单人</label>
                        <div class="layui-input-inline">
                            <input type="text" name="userName" lay-verify="required" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">签单金额</label>
                        <div class="layui-input-inline">
                            <input type="number" name="money" lay-verify="required" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-row layui-col-space10 layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">签单时间</label>
                        <div class="layui-input-inline">
                            <input type="text" name="signTime" id="signTime"  lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input" readonly>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">签单类型</label>
                        <div class="layui-input-inline">
                            <select name="typeID" id="typeID" lay-verify="required" lay-filter="typeID" >
                                <option value="">请选择类型</option>
                                {volist name="type" id="vo"}
                                <option value="{$vo.id}" >{$vo.name}</option>
                                {/volist}
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-row layui-col-space10 layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">客户域名</label>
                        <div class="layui-input-inline">
                            <input type="text" name="url" lay-verify="required" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">是否优化</label>
                        <div class="layui-input-inline">
                            <input type="radio" name="isSeo" value="1" title="是">
                            <input type="radio" name="isSeo" value="0" title="否" checked>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">是否备案</label>
                        <div class="layui-input-inline">
                            <input type="radio" name="isBeiAn" value="1" title="是" lay-filter="isBeiAn">
                            <input type="radio" name="isBeiAn" value="0" title="否" lay-filter="isBeiAn" checked>
                        </div>
                    </div>
                </div>
                <div class="layui-row layui-col-space10 layui-form-item" id="beiAnTextDiv" style="display: none">
                    <label class="layui-form-label">备案备注</label>
                    <div class="layui-input-block">
                        <textarea name="beiAnText" id="beiAnText" class="layui-textarea" style="width: 100%;"></textarea>
                    </div>
                </div>
                <div class="layui-row layui-col-space10 layui-form-item">
                    <label class="layui-form-label">特殊要求</label>
                    <div class="layui-input-block">
                        <textarea name="special" class="layui-textarea" style="width: 100%;"></textarea>
                    </div>
                </div>
                <div class="layui-row layui-col-space10 layui-form-item">
                    <label class="layui-form-label">备注</label>
                    <div class="layui-input-block">
                        <textarea name="content" class="layui-textarea" style="width: 100%;"></textarea>
                    </div>
                </div>

                <div class="layui-form-item layui-layout-admin">
                    <div class="layui-input-block">
                        <div class="layui-footer" style="left: 0;">
                            <button class="layui-btn" lay-submit="" lay-filter="btnAdd">保存</button>
                            <a class="layui-btn layui-btn-primary" href="javascript:parent.location.reload();">返回</a>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
{/block}

{block name="script"}
<script>
    layui.config({
        base: '__STATIC__/layuiadmin/' //静态资源所在路径
    }).extend({
        index: '/lib/index' //主入口模块
    }).use(['index', 'table','form','laydate'], function () {
        var $ = layui.$, form = layui.form, layer = layui.layer, table = layui.table, laydate = layui.laydate;

        laydate.render({elem: '#signTime'});
        form.on('radio(isBeiAn)', function(data){
            var value=data.value; //被点击的radio的value值
            if (value==1)
            {
                $('#beiAnTextDiv').show();
                layer.tips('请输入备案资料', '#beiAnText',{tips: 1});
            }
            else {$('#beiAnTextDiv').hide();}
        });

        form.on('submit(btnAdd)', function (data) {
            $.post("{:url('add')}", data.field, function (result) {
                if (result['code'] == 0) {
                    console.log(result);
                    layer.msg(result['msg'], {icon: 1, time: 1000}, function () {
                        $.post("{:url('sendMail')}",{to:result['email'],name:'“浙江四为网络” - 新网站下单',body:'客服下单啦~ 请去分配!'}, function (result) {
                            if (result['code'] == 0) {
                                layer.msg(result['msg'], {icon: 1, time: 1000}, function () {
                                    parent.location.reload();
                                });
                            } else {
                                layer.msg(result['msg'], {icon: 3, time: 3000});
                            }
                        });
                    });

                } else {
                    layer.msg(result['msg'], {icon: 3, time: 3000});
                }
            });
            return false;
        });
    });
</script>
{/block}